//
//  CRFrinedDetailView.m
//  CRChatRoom
//
//  Created by lanou3g on 15/11/26.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//



#import "CRFrinedDetailView.h"
#import "CRUserDetailModel.h"
#import "UIView+Extension.h"
#import "CRLTVIew.h"
#import "UIImageView+WebCache.h"
#import "CRTextView.h"

#define iconX  35
#define iconY  70
#define iconW 90
//#define margin 35
#define ltViewX 100
#define ltViewW 200
#define ltViewH 30
#define ltViewFont [UIFont systemFontOfSize:14]

@interface CRFrinedDetailView ()<UITextFieldDelegate>

@end

@implementation CRFrinedDetailView

static CGFloat margin = 35;
static CGFloat iconMargin = 30;
static CGFloat buttonMargin = 50;

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupSubView];
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back_girl"]];
    }
    return self;
}

- (void)setupSubView
{
    //360 480
    
    CGFloat Higth = CGRectGetHeight([UIScreen mainScreen].bounds);
    if (Higth == 480) {
        margin = 31;
        iconMargin = 0;
        buttonMargin = 30;
    }
    self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height * 0.25)];
    CGFloat iconH = iconW;
    
    self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(iconX, iconY, iconW, iconH)];
    [self.iconImageView.layer setMasksToBounds:YES];
    [self.iconImageView.layer setCornerRadius:self.iconImageView.width / 2];
    self.iconImageView.backgroundColor = [UIColor lightGrayColor];
    
    
    // 个性签名
    self.signatureview = [[CRTextView alloc] init];
    self.signatureview.font = [UIFont systemFontOfSize:12];
    self.signatureview.layer.borderWidth = 2;
    self.signatureview.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor colorWithRed:0.574 green:0.667 blue:0.039 alpha:1.000]);
    self.signatureview.layer.cornerRadius = 5;
    self.signatureview.clipsToBounds = YES;
    
    
    CGFloat signX = iconX + iconW + 20;
    self.signatureview.frame = CGRectMake(signX, iconY, self.width - signX - 20, iconH);
    self.signatureview.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    self.signatureview.placeHolderString = @"请输入签名...";
    self.signatureview.textColor = [UIColor whiteColor];
    self.userNameLable = [self LTViewInitWithTitle:@"名称"];
    self.userNameLable.y = iconY + iconH + iconMargin;
    
    
    self.nicknameLable = [self LTViewInitWithTitle:@"备注"];
    self.nicknameLable.y = self.userNameLable.y + margin;
    
    self.gengerLable = [self LTViewInitWithTitle:@"性别"];
    self.gengerLable.y = self.nicknameLable.y + margin;
    
    self.ageLable = [self LTViewInitWithTitle:@"年龄"];
    self.ageLable.y = self.gengerLable.y + margin;
    
    self.birthdayLable = [self LTViewInitWithTitle:@"生日"];
    self.birthdayLable.y = self.ageLable.y + margin;
    
    self.jobLable = [self LTViewInitWithTitle:@"工作"];
    self.jobLable.y = self.ageLable.y + margin + margin * 1.5;
    
    self.address = [self LTViewInitWithTitle:@"住址"];
    self.address.y = self.jobLable.y + margin;
    
    self.hometownLable = [self LTViewInitWithTitle:@"家乡"];
    self.hometownLable.y = self.address.y + margin;
    
    self.hobbyLable = [self LTViewInitWithTitle:@"兴趣"];
    self.hobbyLable.y = self.hometownLable.y + margin;
    
    self.chatButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.chatButton.frame = CGRectMake(0, self.hobbyLable.y + buttonMargin, 200, 30);
    self.chatButton.centerX = self.centerX;
    [self.chatButton setTitle:@"提交" forState:UIControlStateNormal];
    
    
    [self addSubview:self.headView];
    [self addSubview:self.iconImageView];
    [self addSubview:self.signatureview];
//    [self addSubview:self.userNameLable];
//    [self addSubview:self.nicknameLable];
//    [self addSubview:self.gengerLable];
//    [self addSubview:self.ageLable];
//    [self addSubview:self.birthdayLable];
//    [self addSubview:self.jobLable];
//    [self addSubview:self.address];
//    [self addSubview:self.hometownLable];
//    [self addSubview:self.hobbyLable];
    [self addSubview:self.chatButton];
    
    
}
- (void)setFriendDetailModel:(CRUserDetailModel *)friendDetailModel
{
    _friendDetailModel = friendDetailModel;
    
    self.headView.image = [UIImage imageNamed:@"backgroud"];
    
    // 头像
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:friendDetailModel.iconUrl]];
    // 个性签名
    self.signatureview.text = friendDetailModel.signature;
    self.userNameLable.rightField.text = friendDetailModel.username;
    self.nicknameLable.rightField.text = friendDetailModel.remarkName;
    self.gengerLable.rightField.text = friendDetailModel.gender;
    self.ageLable.rightField.text = friendDetailModel.age;
    self.birthdayLable.rightField.text = friendDetailModel.brithday;
    self.jobLable.rightField.text = friendDetailModel.job;
    self.address.rightField.text = friendDetailModel.address;
    self.hometownLable.rightField.text = friendDetailModel.hometown;
    self.hobbyLable.rightField.text = friendDetailModel.hobby;
}



- (CRLTVIew *)LTViewInitWithTitle:(NSString *)title
{
    CRLTVIew *ltView = [[CRLTVIew alloc] init];
    ltView.leftLable.font = ltViewFont;
    ltView.rightField.font = ltViewFont;
    ltView.leftLable.textAlignment = NSTextAlignmentLeft;
    ltView.rightField.textAlignment = NSTextAlignmentLeft;
    ltView.width = ltViewW;
    ltView.x = ltViewX;
    ltView.height = ltViewH;
    ltView.leftLable.text = title;
    ltView.centerX= self.centerX;
    ltView.leftLable.textColor = [UIColor whiteColor];
    [self addSubview:ltView];
    ltView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    //    ltView.rightField.backgroundColor = [UIColor whiteColor];
    
    return ltView;
}






@end
